package controller

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"strconv"
	"web_app/logic"
)

func CommunityHandler(c *gin.Context) {

	coms := logic.GetCommunityList()
	if coms == nil {
		zap.L().Error("Community表没查询到任何数据")
		ResponseError(c, CodeServerBusy)
		return
	}
	ResponseSuccess(c, coms)
}

func CommunityDetailHandler(c *gin.Context) {

	idStr := c.Param("id")
	i, err := strconv.ParseInt(idStr, 10, 64)
	if err != nil {
		ResponseError(c, CodeInvalidParam)
		return
	}

	community := logic.GetCommunityDetail(i)

	if community == nil {
		zap.L().Error("无效id")
		ResponseError(c, CodeInvalidID)
		return
	}

	ResponseSuccess(c, community)

}
